<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../jquery-easyui-1.5.2/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../jquery-easyui-1.5.2/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../jquery-easyui-1.5.2/demo.css">
		<link rel="stylesheet" type="text/css" href="../../style/syExtIcon.css">

		<script type="text/javascript" src="../../jquery-easyui-1.5.2/jquery.min.js"></script>
		<script type="text/javascript" src="../../jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../js/syExtEasyUI.js"></script>
		<script type="text/javascript" src="../../js/syExtHighcharts.js"></script>
		<script type="text/javascript" src="../../js/syExtJavascript.js"></script>
		<script type="text/javascript" src="../../js/syExtJquery.js"></script>
		<script type="text/javascript">
			var label;
			var submitNow = function($parentId, $dialog, $tree, $pjq) {
				if(!$('#form').form("validate")) {
					return;
				}
				var tabs = $("#tab").tabs("tabs");
				var ds = [];
				for(var i in tabs) {
					var tab = tabs[i];
					var page = tab.find('iframe').get(0).contentWindow;
					var rows = page.getPriceInfo();
					for(var j in rows) {
						if((rows[j].price2!=null&&rows[j].price3 == null) || (rows[j].price3!=null&&rows[j].price3.trim() == "")) {
							sy.info("时段收费数据不完整！")
							return;
						}
					}
					var f = page.getFormInfo();
					$.extend(f, {
						rows: rows
					});
					ds.push(f)
				}

				var url = '/carpark/addTempCharge';
				var data = sy.serializeObject($('#form'));
				if(data.id == null) {
					data.carparkId = $parentId;
				}
				if(parent.tempChargeData != null) {
					data.carparkId = parent.tempChargeData.carpark.id;
				}
				$.extend(data, {
					ds: sy.jsonToString(ds)
				})
				$.post(url, data, function(result) {
					if(result.success) {
						$pjq.messager.alert('提示', result.msg, 'info');
						parent.loadDataGrid();
						$dialog.dialog('destroy');
					} else {
						$pjq.messager.alert('提示', result.msg, 'error');
					}
				}, 'json');
			}
			var ds;
			var loadForm = function(data) {
				if(data == null) {
					return;
				}
				$("#form").form("load", {
					"id": data.id,
					"code": data.code,
					"name": data.name,
					"carparkDurationType": data.carparkDurationTypeEnum,
					"onedayMaxCharge": data.onedayMaxCharge,
					"freeTime": data.freeTime,
					"carparkAcrossDayType": data.carparkAcrossDayTypeEnum,
					"acrossdayChargeEnable": data.acrossdayChargeEnable,
					"acrossDayPrice": data.acrossDayPrice,
					"acrossDayIsFree": data.acrossDayIsFree,
					"carparkHolidayType": data.carparkHolidayTypeEnum,
					"carType": data.carparkCarType.name,
					"using":data.using,
				});
				ds = data.carparkDurationStandards
				addDuration(ds[0]);
				if(data.carparkHolidayTypeEnum == '非工作日') {
					document.getElementById("haveHolidayChecked").checked = true;
				} else {
					document.getElementById("haveHolidayChecked").checked = false;
				}
				if(data.freeTime > 0) {
					document.getElementById("havaFreeTimeChecked").checked = true;
				} else {
					document.getElementById("havaFreeTimeChecked").checked = false;
				}
			}
			$(function() {
				haveFreeChange(false);
				haveHolidayChange(false);
				loadCarType();
				if(parent.tempChargeData == null) {
					return;
				}
				
				loadForm(parent.tempChargeData);
			});

			function loadCarType() {
				$.post("/carpark/listCarTypes", {}, function(d) {
					$("#carType").combobox({
						data:d,
						textField:"name",
						valueField:"name",
					})
					$("#carType").combobox("setValue",d[0].name);
				})
				
			}

			function createRows(form, t) {
				var title = $("#tab").tabs("getSelected").panel("options").title;
				var sd = title.split("-")[0];
				var ed = title.split("-")[1];
				if(!form.form("validate")) {
					return;
				}
				var d = sy.serializeObject(form);
				var ft = $("#freeTime").textbox("getValue");
				$.extend(d, {
					freeTime: ft,
					startTimeLabel: sd,
					endTimeLabel: ed,
				});
				$.post("/carpark/countDurationPrice", d, function(data) {
					if(data.success) {
						t.datagrid({
							data: data.obj,
							onDblClickCell: function(index, field, row) {
								if(field == "price3") {
									t.datagrid("beginEdit", index);
								} else {
									t.datagrid('updateRow', {
										index: index,
										row: {}
									});
									t.datagrid("endEdit", index);
								}

							},

						});
					}
				});
			}
			var durations = []

			function addDuration(data) {
				$.messager.progress({
					title: "提示",
					msg: "数据加载中"
				});
				var sh = $("#startTimespinner").timespinner("getHours");
				var eh = $("#endTimespinner").timespinner("getHours");
				if(sh.length == 1 || sh < 10) {
					sh = "0" + sh + ":00";
				} else {
					sh = sh + ":00";
				}
				if(eh.length == 1 || eh < 10) {
					eh = "0" + eh + ":00";
				} else {
					eh = eh + ":00";
				}
				if(data != null) {
					sh = data.startTimeLabel;
					eh = data.endTimeLabel;
					durations.push({
						title: sh + "-" + eh,
						data: data
					});
				} else {

				}
				var title = sh + "-" + eh;
				var content = '<div style="height: 100%; width: 100%;overflow:hidden"><iframe scrolling="no" frameborder="0"  src="duration.html?title=' + title + '" style="width:100%;height:100%;"></iframe></div>';
				if($('#tab').tabs("exists", title)) {
					sy.info("已存在" + title + "的时段")
					return;
				}
				$('#tab').tabs('add', {
					title: title,
					content: content,
				});
			}

			function inifDurationsInfo(form, table) {
				if(ds == null) {
					$.messager.progress("close");
				}
				var tabs = $("#tab").tabs("tabs");
				var data = ds[tabs.length - 1];
				form.form("load", {
					"startTimeLabel": data.startTimeLabel,
					"endTimeLabel": data.endTimeLabel,
					"startStepTime": data.startStepTime,
					"startStepPrice": data.startStepPrice,
					"maxPrice": data.maxPrice,
					"unitDuration": data.unitDuration,
					"unitPrice": data.unitPrice,
					"crossDayUnitDuration": data.crossDayUnitDuration,
					"crossDayPrice": data.crossDayPrice,
				});
				if(data.tempObject != null) {
					table.datagrid({
						data: data.tempObject
					})
				}
				if(ds.length > tabs.length) {
					addDuration(ds[tabs.length]);
				} else {
					$.messager.progress("close");
				}
			}

			function deleteDuration() {
				var tab = $('#tab').tabs('getSelected');
				var index = $('#tab').tabs('getTabIndex', tab);
				$('#tab').tabs('close', index);
			}

			function haveFreeChange(cb) {
				$("#freeTime").numberbox("readonly", !cb);
				$("#acrossdayChargeEnable").combobox("readonly", !cb);
				document.getElementById("acrossDayIsFree").disabled = !cb;
			}

			function haveHolidayChange(cb) {
				$("#carparkHolidayType").combobox("readonly", !cb);
			}
		</script>
		<style>
			.dform {}
		</style>
	</head>

	<body>
		<form id="form" method="post" style="">
			<div>
				<table class="table" style="width: 100%;">
					<tr style="display: none;">
						<td>id</td>
						<td><input name="id" value="" />
						<input name="using" value="" /> </td>
					</tr>
					<tr>
						<td>收&ensp;&ensp;费&ensp;编&ensp;码</td>
						<td><input class="easyui-textbox" name="code" data-options="required:true" style="width: 100px;" /> </td>
						<td>收&ensp;&ensp;费&ensp;名&ensp;称</td>
						<td><input class="easyui-textbox" name="name" data-options="required:true" style="width: 100px;" /></td>
						<td>&ensp;跨&ensp; 天&ensp; 标&ensp; 准</td>
						<td>
							<select class="easyui-combobox" name="carparkDurationType" style="width: 100px;">
								<option value="进场时长">进场时长</option>
								<option value="自然天">自然天</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>一天最大收费</td>
						<td><input class="easyui-numberbox" value="0" name="onedayMaxCharge" data-options="required:true" style="width: 100px;" /> </td>
						<td>车&ensp;&ensp;辆&ensp;类&ensp;型</td>
						<td>
							<select id="carType" name="carType" class="easyui-combobox" style="width: 100px;">
								
							</select>
						</td>
						<td><input id="haveHolidayChecked" type="checkbox" onchange="haveHolidayChange(this.checked);" />工 作 日 类 型</td>
						<td>
							<select id="carparkHolidayType" class="easyui-combobox" name="carparkHolidayType" style="width: 100px;">
								<option value="工作日">工作日</option>
								<option value="非工作日">非工作日</option>
							</select>
						</td>
					</tr>
					<tr>
						<td><input id="havaFreeTimeChecked" type="checkbox" onchange="haveFreeChange(this.checked);" />&ensp; 免费时长</td>
						<td><input id="freeTime" name="freeTime" class="easyui-numberbox" data-options="required:true" style="width: 100px;" value="0" /> </td>
						<td>免费时长收费</td>
						<td>
							<select id="acrossdayChargeEnable" name="acrossdayChargeEnable" class="easyui-combobox" style="width: 100px;">
								<option value="1">是</option>
								<option value="0">否</option>
							</select>
						</td>
						<td><input id="acrossDayIsFree" name="acrossDayIsFree" value="true" type="checkbox" />跨天继续免费</td>
						<td></td>
					</tr>
					<tr>
						<td>跨天计费时长</td>
						<td>
							<select name="carparkAcrossDayType" class="easyui-combobox" value="当天时长" style="width: 100px;">
								<option value="当天时长">当天时长</option>
								<option value="跨天时长">跨天时长</option>
							</select>
						</td>
						<td>跨天额外收费</td>
						<td><input name="acrossDayPrice" class="easyui-numberbox" style="width: 100px;" value="0" /> </td>
						<td></td>
						<td></td>
					</tr>
				</table>
				<table>
					<tr>
						<td>收费时段设置</td>
						<td><input id="startTimespinner" class="easyui-timespinner" style="width: 80px;" value="00:00" /> </td>
						<td><input id="endTimespinner" class="easyui-timespinner" style="width: 80px;" value="00:00" /></td>
						<td>
							<a class="easyui-linkbutton" href="javascript:void(0)" onclick="addDuration();">添加时段</a>
						</td>
						<td>
							<a class="easyui-linkbutton" href="javascript:void(0)" onclick="deleteDuration();">删除时段</a>
						</td>
					</tr>
				</table>
			</div>
		</form>
		<div id="tab" class="easyui-tabs" style="width: 100%;height: 350px;">

		</div>

	</body>

</html>